define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	
	$scope.form.id = params.id;
	$scope.form.fk_organization = params.fk_organization;
	httpService.post(app.urls.organization_selectUuserOrganizationIfExit,{"id":params.id,"fk_organization":params.fk_organization}, function (data) {
		if("0000" === data.code){
			$scope.form.fk_user = data.data.fk_user;
		}else{
			alert(data.msg);
		}
	});


	$scope.find= function(){
	//查询现属部门
	httpService.post(app.urls.organization_selectByUserOrganization,$scope.form,function(data){
		if("0000" === data.code){
		$scope.findOrg();
		}else{
			alert(data.msg);
		}
	});
	}
	$scope.find();
	
	$scope.findOrg = function(){
	//查询部门
	httpService.post(app.urls.organization_selectByUnit,$scope.form,function(data){
		if("0000" === data.code){
			$scope.orgs = data.data;
		}else{
			alert(data.msg);
		}
	});
	}
		$scope.saveForm = function() {
			if ($scope.formCheck()) {
				httpService.post(app.urls.organization_selectUuserOrganizationIfExit,{"fk_organization":$scope.form.fk_organization,"fk_user":$scope.form.fk_user}, function (data) {
					if ("0000" === data.code) {
						if (data.data == null) {
							httpService.post(app.urls.organization_updateUserOrganization, $scope.form, function (data) {
								if ("0000" === data.code) {
									var data = {id: $scope.form.fk_organization, type: params.type};
									eventBusService.publish("content.page.reload", data);
									eventBusService.publish("modal.page.close", {});
								} else {
									alert(data.msg);
								}
							});
						} else {
							alert("该组织下已有该人员，无需重复添加");
						}
					} else {
						alert(data.msg);
					}
				});
			}
}}}});